package com.zqxx.examine.management.controller.action;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.extr.file.util.FileUploadUtil;
import com.zqxx.examine.management.security.UserInfo;

@Controller
public class TrainingAction
{
  @RequestMapping(value={"/secure/upload-uploadify-file"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
  @ResponseBody
  public String uploadFile(HttpServletRequest request, HttpServletResponse response)
  {
    UserInfo userInfo = (UserInfo)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    List<String> filePathList = new ArrayList();
    try
    {
      filePathList = FileUploadUtil.uploadFile(request, response, userInfo.getUsername());
    }
    catch (FileNotFoundException e)
    {
      e.printStackTrace();
    }
    catch (Exception ex)
    {
      ex.printStackTrace();
    }
    if (filePathList.size() == 0) {
      return "系统错误";
    }
    return (String)filePathList.get(0);
  }
}

